package ks.client.controllers.commands;

import org.w3c.dom.Document;

import ks.client.kommander.Action;
import ks.client.lobby.Lobby;
import ks.framework.common.Message;

public class RejectCommandController {
	private Lobby lobby;
	
	public RejectCommandController(Lobby l) {
		this.lobby = l;
	}
	
	/**
	 * Just send the reject command.
	 * 
	 * @param tableNum
	 * @param player
	 */
	public void send(int tableNum, String player) {
		String uid = lobby.getKommander().generateUid();
		
		StringBuilder sb = new StringBuilder("<command version=\"1.0\" id=\"" + uid + "\">");
		sb.append("<reject table=\"" + tableNum + "\" player=\"" + player + "\"/>");
		sb.append("</command>");
		
		Document d = Message.construct(sb.toString());
		Message m = new Message(d);
		lobby.getUserContext().getClient().sendToServer(m);
	}
	
	/**
	 * Send the reject command and perform an Action on ack/nack.
	 * 
	 * @param tableNum
	 * @param player
	 * @param action
	 */
	public void send(int tableNum, String player, Action action) {
		String uid = lobby.getKommander().generateUid();
		
		StringBuilder sb = new StringBuilder("<command version=\"1.0\" id=\"" + uid + "\">");
		sb.append("<reject table=\"" + tableNum + "\" player=\"" + player + "\"/>");
		sb.append("</command>");
		
		lobby.getKommander().addAction(uid, action);
		
		Document d = Message.construct(sb.toString());
		Message m = new Message(d);
		lobby.getUserContext().getClient().sendToServer(m);
	}
}